import Vue from "vue";
import ElementUI from "element-ui";
import "element-ui/lib/theme-chalk/index.css";
import "vue-awesome/icons";
import Icon from "vue-awesome/components/Icon";
import "normalize.css";

import App from "./App.vue";
import router from "./router/index";
import store from "./store";

Vue.config.productionTip = false;

Vue.use(ElementUI);
Vue.component("icon", Icon);

router.beforeEach((to, from, next) => {
  if (to.path == "/login") {
    sessionStorage.removeItem("user");
  }
  let user = JSON.parse(sessionStorage.getItem("user"));
  if (!user && to.path != "/login") {
    next({path: "/login"});
  } else {
    next();
  }
});

new Vue({
  router,
  store,
  render: (h) => h(App),
}).$mount("#app");
